package logic

import (
	"context"
	"four/sss/weeekrpc/weeekrpcclient"

	"four/sss/weeekapi/internal/svc"
	"four/sss/weeekapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UploadLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUploadLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UploadLogic {
	return &UploadLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}
func (l *UploadLogic) Upload(req *types.UploadRequest) (resp *types.UploadResponse, err error) {
	// todo: add your logic here and delete this line
	userid := req.Userid
	file := req.File         //todo: 文件名
	fileName := req.FileName //todo: 文件后缀
	capacity := req.Capacity
	size := req.Size
	src := req.Src
	var r types.UploadResponse
	r.Code = -1
	r.Capacity = 0
	_, err = l.svcCtx.WeekRpc.Upload(l.ctx, &weeekrpcclient.UploadRequest{
		Userid:   int64(userid),
		FileName: file,
		SuxName:  fileName,
		Capacity: int64(capacity),
		Size:     int64(size),
		Src:      src,
	})
	if err != nil {
		r.Msg = err.Error()
		return &r, nil
	}
	r.Code = 200
	r.Msg = "上传成功"
	r.Capacity = capacity
	return &r, nil
}
